function getElementByStyleClass(clazz){
	try{
		var toReturn = $('.'+clazz);
		return toReturn[0];
	} catch (e) {
		return null;
	}
}

function appendText(node,txt){
	node.appendChild(document.createTextNode(txt));
}

function changeStyleClass(element, clazz){
	element.setAttribute("class", clazz);
}

function isValidEmail(email){
	var exclude=/[^@\-\.\w]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/;
	var check=/@[\w\-]+\./;
	var checkend=/\.[a-zA-Z]{2,3}$/;
	if(((email.search(exclude) != -1)||(email.search(check)) == -1)||(email.search(checkend) == -1)){
		return false;
	}
	else {
		return true;
	}
}

function emailValidator(element,element_to_put_message, messageInvalid ){
	var email = element.value;
	if (!isValidEmail(email)) {
		element_to_put_message.innerHTML = "";
		appendText(element_to_put_message,messageInvalid);
		changeStyleClass(element_to_put_message, 'ui-message-error ui-widget ui-corner-all');
		element_to_put_message.style.width = '140px';
	} else{
		element_to_put_message.innerHTML = "";
		element_to_put_message.style.width = '0px';
		changeStyleClass(element_to_put_message,'');
	}
}

function closeAfterRequest(xhr, status, args){
	return args.close;
}


function writeObj(obj, message) {
	  if (!message) { message = obj; }
	  var details = "*****************" + "\n" + message + "\n";
	  var fieldContents;
	  for (var field in obj) {
	    fieldContents = obj[field];
	    if (typeof(fieldContents) == "function") {
	      fieldContents = "(function)";
	    }
	    details += "  " + field + ": " + fieldContents + "\n";
	  }
	  alert(details);
}
